<template>
  <div class="">
    <sec-form
      ref="formDataRef"
      :ruleForm="ruleForm"
      :formData="formData"
      :optionData="optionData"
      :rules="rules"
      :hideProp="hideProp"
    ></sec-form>
  </div>
</template>
<script>
import { approvalUserApi } from "api/app/userApi";
export default {
  name: "",
  props: {
    data: Object,
  },
  components: {},
  computed: {},
  data() {
    return {
      ruleForm: {
        status: "",
        reason: "",
        remark: "",
      },
      hideProp: {
        reason: true,
        remark: true,
      },
      optionData: {
        status: this.$store.state.dict.status.slice(0, 2),
        reason: [
          { label: "姓名不符", value: "姓名不符" },
          { label: "公司名称不符", value: "公司名称不符" },
          { label: "信息不符", value: "信息不符" },
        ],
      },
      rules: {
        status: this.config.selectRule,
        reason: this.config.selectRule,
      },
    };
  },
  created() {
    this.formData = [
      { type: "select", label: "最终结果", prop: "status" },
      { type: "select", label: "拒绝原因", prop: "reason" },
      { type: "textarea", label: "详细说明", prop: "remark" },
      {
        type: "operation",
        children: [
          {
            label: "确 定",
            icon: "el-icon-tickets",
            click: () => {
              if (this.$refs.formDataRef.validate()) {
                if (this.ruleForm.status === "pass") {
                  this.ruleForm.reason = "";
                  this.ruleForm.remark = "";
                }
                this.approvalUser();
              }
            },
          },
        ],
      },
    ];
  },
  mounted() {},
  methods: {
    approvalUser() {
      approvalUserApi({ ...this.ruleForm, phone: this.data.phone }).then((res) => {
        let state = this.message.state(res);
        if (!state) return;
        this.$emit("confirm");
      });
    },
  },
  watch: {
    "ruleForm.status": {
      handler(newVal) {
        if (newVal === "fail") {
          this.hideProp.reason = false;
          this.hideProp.remark = false;
        } else {
          this.hideProp.reason = true;
          this.hideProp.remark = true;
        }
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>
<style lang="scss" scoped></style>
